package org.hako.recite.word.tool;

import org.hako.recite.word.parser.WordList;
import org.hako.recite.word.parser.WordListParseException;
import org.hako.recite.word.parser.factory.WordListParserFactory;
import org.hako.recite.word.parser.impl.UnsupportedFileExtensionException;
import org.hako.recite.word.review.ReviewWordsProvider;
import org.hako.recite.word.review.WordListReviewWordsProvider;
import org.hako.recite.word.review.WordReviewFrame;

/**
 * Program entry point for reviewing words.
 * 
 * @since 0.4.10
 * @author <a href="mailto:xnnyygn@gmail.com">xnnyygn</a>
 */
public class ReviewWords {

	/**
	 * Main.
	 * 
	 * @param args
	 * @throws UnsupportedFileExtensionException
	 * @throws WordListParseException
	 */
	public static void main(String[] args) throws WordListParseException,
			UnsupportedFileExtensionException {
		int argumentCount = args.length;
		if (argumentCount < 1) {
			showUsage();
			return;
		}
		WordListParserFactory parserFactory = new WordListParserFactory();
		String filePath = args[0];
		int startIndex = argumentCount >= 2 ? Integer.parseInt(args[1]) : 0;
		WordList wordList = parserFactory.getParser(filePath).parse(filePath);
		if (wordList.getWordCount() == 0) {
			
			// no word to review
			return;
		}
		ReviewWordsProvider provider = new WordListReviewWordsProvider(wordList);
		WordReviewFrame frame = new WordReviewFrame(provider, startIndex);
		frame.show();
	}

	/**
	 * Show usage.
	 */
	private static void showUsage() {
		System.out.println("usage <wordListFilePath> [<startIndex=0>]");
	}
}
